﻿#region Using...

using System;
using System.Web;
using eCommerce.Core;
using eCommerce.Services.Messages;

#endregion

namespace eCommerce
{
    public delegate LocalizedString Localizer(string key);

    public abstract class WebViewPage<TModel> : System.Web.Mvc.WebViewPage<TModel>
    {
        private IMessageService _messageService;

        protected WebViewPage()
        {
            _messageService = EngineContext.Current.Resolve<IMessageService>();
        }

        private Localizer _localizer;

        public Localizer T
        {
            get
            {
                if (_localizer == null)
                {
                    _localizer = (key) =>
                    {
                        //var result = _localizationService.GetResource(key);
                        var result = _messageService.GetResourceValue(key,0);
                        return new LocalizedString(result);
                        //return null;
                    };

                }
                return _localizer;

            }
        }

    }

    public class LocalizedString : MarshalByRefObject, IHtmlString
    {
        private readonly string _localized;

        public LocalizedString(string localized)
        {
            _localized = localized;
        }

        public string ToHtmlString()
        {
            return _localized;
        }
    }

    public abstract class WebViewPage : WebViewPage<dynamic>
    {
        protected WebViewPage()
        {
        }
    }
}